package com.zlict.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.enums.BusinessType;
import com.zlict.admin.domain.CostTypeTree;
import com.zlict.admin.service.ICostTypeTreeService;
import com.zlict.common.utils.poi.ExcelUtil;
import com.zlict.common.core.page.TableDataInfo;

/**
 * 费用类型树形Controller
 * 
 * @author lqh
 * @date 2025-06-21
 */
@RestController
@RequestMapping("/admin/costTree")
@RequiredArgsConstructor
public class CostTypeTreeController extends BaseController
{
    private final  ICostTypeTreeService costTypeTreeService;

    /**
     * 查询费用类型树形列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:costTree:list')")
    @GetMapping("/list")
    public TableDataInfo list(CostTypeTree costTypeTree)
    {
        startPage();
        List<CostTypeTree> list = costTypeTreeService.selectCostTypeTreeList(costTypeTree);
        return getDataTable(list);
    }

    /**
     * 导出费用类型树形列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:costTree:export')")
    @Log(title = "费用类型树形", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CostTypeTree costTypeTree)
    {
        List<CostTypeTree> list = costTypeTreeService.selectCostTypeTreeList(costTypeTree);
        ExcelUtil<CostTypeTree> util = new ExcelUtil<CostTypeTree>(CostTypeTree.class);
        util.exportExcel(response, list, "费用类型树形数据");
    }

    /**
     * 获取费用类型树形详细信息
     */
//    @PreAuthorize("@ss.hasPermi('admin:costTree:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(costTypeTreeService.selectCostTypeTreeById(id));
    }

    /**
     * 新增费用类型树形
     */
//    @PreAuthorize("@ss.hasPermi('admin:costTree:add')")
    @Log(title = "费用类型树形", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CostTypeTree costTypeTree)
    {
        return toAjax(costTypeTreeService.insertCostTypeTree(costTypeTree));
    }

    /**
     * 修改费用类型树形
     */
//    @PreAuthorize("@ss.hasPermi('admin:costTree:edit')")
    @Log(title = "费用类型树形", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CostTypeTree costTypeTree)
    {
        return toAjax(costTypeTreeService.updateCostTypeTree(costTypeTree));
    }

    /**
     * 删除费用类型树形
     */
//    @PreAuthorize("@ss.hasPermi('admin:costTree:remove')")
    @Log(title = "费用类型树形", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(costTypeTreeService.deleteCostTypeTreeByIds(ids));
    }

    /**
     * 查询所有费用类型树形
     * @return
     */
    @GetMapping("/selectAllCostTypeTree")
    public AjaxResult selectAllCostTypeTree()
    {
        return success(costTypeTreeService.selectAllCostTypeTree());
    }
}
